package com.ruoyi.sgsc.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.common.annotation.Anonymous;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.sgsc.domain.orders;
import com.ruoyi.sgsc.service.IordersService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 订单Controller
 * 
 * @author wy
 * @date 2024-09-29
 */
@Anonymous
@RestController
@RequestMapping("/sgsc/orders")
public class ordersController extends BaseController
{
    @Autowired
    private IordersService ordersService;

    /**
     * 查询订单列表
     */
    @GetMapping("/list")
    public TableDataInfo list(orders orders)
    {
        startPage();
        List<orders> list = ordersService.selectordersList(orders);
        return getDataTable(list);
    }

    /**
     * 导出订单列表
     */

    @PostMapping("/export")
    public void export(HttpServletResponse response, orders orders)
    {
        List<orders> list = ordersService.selectordersList(orders);
        ExcelUtil<orders> util = new ExcelUtil<orders>(orders.class);
        util.exportExcel(response, list, "订单数据");
    }

    /**
     * 获取订单详细信息
     */

    @GetMapping(value = "/{orderId}")
    public AjaxResult getInfo(@PathVariable("orderId") Long orderId)
    {
        return success(ordersService.selectordersByOrderId(orderId));
    }

    /**
     * 获取最新一条订单id
     * @return
     */
    @GetMapping(value = "/last/date")
    public AjaxResult getOrderId()
    {
        return success(ordersService.selectordersByDate());
    }
    /**
     * 新增订单
     */

    @PostMapping
    public AjaxResult add(@RequestBody orders orders)
    {
        return toAjax(ordersService.insertorders(orders));
    }

    /**
     * 修改订单
     */

    @PutMapping
    public AjaxResult edit(@RequestBody orders orders)
    {
        return toAjax(ordersService.updateorders(orders));
    }

    /**
     * 删除订单
     */

	@DeleteMapping("/{orderIds}")
    public AjaxResult remove(@PathVariable Long[] orderIds)
    {
        return toAjax(ordersService.deleteordersByOrderIds(orderIds));
    }
}
